package main

import (
	"fmt"
	"goGin/router"

	"goGin/tools"

	"github.com/garyburd/redigo/redis"
	"github.com/gin-gonic/gin"
)

func main() {
	router.Include(router.Index)
	router.Include(router.Ws)
	router.Include(router.Demo)
	router.Include(router.Friend)
	router.Include(router.Others)
	c, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		fmt.Println("conn redis failed,", err)
		// return
	}
	// _, err = c.Do("Set", "abc", "{'asd':10}")
	if err != nil {
		fmt.Println(err)
		// return
	}
	// 初始化路由
	config := tools.Initconfig
	// config.Database = "mysql"
	db := tools.InitDB(config)
	r := router.Inits(db, c)
	r.GET("/asd", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	// _, err := r.Run("0.0.0.0:80") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
	if err := r.Run("0.0.0.0:80"); err != nil {
		fmt.Printf("startup service failed, err:%v\n", err)
	}
}
